/**
 * The class defining a series of Data
 * @author  Lorenzo Baracchi <lorenzo.baracchi@usi.ch>
 */

/**
 * Defines the Data class for:
 * 	- the desired type (bars, lines, etc)
 *  - the identifier of the series of data, aka its name
 *  - the color of the series
 *  - optionally y-position defines in which position displays the data (used for staked-bars)
 */
function Data(type, id, color, yPosition) {
	this.id = id;
	this.type = type;
	this.color = color;
	this.x = new Array();
	this.y = new Array();
	this.information = new Array();
	this.yPos = typeof yPosition !== 'undefined' ? yPosition : 0;
	this.selectedFunction = null; //is the function to call when the data is selected 
	
	this.shapes = new Array()
	
	/**
	 * Add one data to the list of data
	 * specify the position of the data x,y and add some additional information
	 * information is optional
	 */
	this.add = function (x,y,info){
		var info = typeof info !== 'undefined' ? info : "";
		this.x.push(x);
		this.y.push(y);
		this.information.push(info);
		this.shapes.push(null);
	}
	
	/**
	 * Get the data at the given index
	 * return an array with [x,y,information]
	 */
	this.getDataAt = function (index) {
		return [this.x[index], this.y[index], this.information[index]];
	}
	
	/**
	 * Get all the data
	 * return an array with [x,y,information]
	 */
	this.getData = function () {
		return [this.x, this.y, this.information];
	}
	
	this.addShape = function(s) {
		this.shapes.push(s);
	}
	
	this.setShape = function(index, s) {
		this.shapes[index]=s;
	}
	
	this.setSelectedFunction = function(funct) {
		this.selectedFunction = funct;
	}
	
	this.getColor = function() {
		if(typeof this.color == Color)
			return color.toString();
		else
			return color;
	}
	
//	/**
//	 * Modify the data at the given index
//	 */
//	this.modifyDataAt = function(index, x, y, info) {
//		x = typeof x != 'undefines' ? x : this.x[index];
//		y = typeof y != 'undefines' ? y : this.y[index];
//		info = typeof info !== 'undefined' ? info : this.information[index];
//		
//		this.x[index] = x;
//		this.x[index] = y;
//		this.information[index] = info;
//	}
//	
//	/**
//	 * Delete the element at the given position
//	 */
//	this.deleteDataAt = function(index) {
//		this.x.splice(index, index);
//		this.y.splice(index, index);
//		this.information.splice(index, index);
//	}
}

/**
 * Function defining a Color given
 */
function Color(red, green, blue, alpha){
	this.red = red;
	this.green = green;
	this.blue = blue;
	this.alpha = (typeof alpha == 'undefined') ? 1 : alpha;
	
	this.toString = function (){
		return "rgba("+this.red+","+this.green+","+this.blue+","+this.alpha+")";
	}
}

